home *** CD-ROM | disk | FTP | other *** search
/ Visual Basic Source Code / Visual Basic Source Code.iso / vbsource / scrolvb / scroll_1.frm (.txt) < prev    next >
Encoding:
Visual Basic Form  |  1996-06-12  |  9.1 KB  |  245 lines

  1. VERSION 2.00
  2. Begin Form frmMain 
  3.    Caption         =   "scroll_1 Demo"
  4.    ClientHeight    =   2775
  5.    ClientLeft      =   1710
  6.    ClientTop       =   1845
  7.    ClientWidth     =   3735
  8.    Height          =   3180
  9.    Icon            =   scroll_1.FRX:0000
  10.    Left            =   1650
  11.    LinkTopic       =   "Form1"
  12.    ScaleHeight     =   185
  13.    ScaleMode       =   3  'Pixel
  14.    ScaleWidth      =   249
  15.    Top             =   1500
  16.    Width           =   3855
  17.    Begin PictureBox picCorner 
  18.       BackColor       =   &H00C0C0C0&
  19.       Height          =   255
  20.       Left            =   120
  21.       ScaleHeight     =   225
  22.       ScaleWidth      =   225
  23.       TabIndex        =   3
  24.       Top             =   120
  25.       Width           =   255
  26.    End
  27.    Begin CommandButton cmdStart 
  28.       Caption         =   "&Start"
  29.       Height          =   375
  30.       Left            =   2040
  31.       TabIndex        =   0
  32.       Top             =   120
  33.       Width           =   1575
  34.    End
  35.    Begin VScrollBar vsb1 
  36.       Height          =   1455
  37.       LargeChange     =   50
  38.       Left            =   120
  39.       SmallChange     =   10
  40.       TabIndex        =   2
  41.       Top             =   480
  42.       Width           =   255
  43.    End
  44.    Begin HScrollBar hsb1 
  45.       Height          =   255
  46.       LargeChange     =   50
  47.       Left            =   480
  48.       SmallChange     =   10
  49.       TabIndex        =   1
  50.       Top             =   120
  51.       Width           =   1455
  52.    End
  53.    Begin PictureBox picBig 
  54.       BackColor       =   &H00FFFF00&
  55.       BorderStyle     =   0  'None
  56.       Height          =   2055
  57.       Left            =   480
  58.       ScaleHeight     =   137
  59.       ScaleMode       =   3  'Pixel
  60.       ScaleWidth      =   209
  61.       TabIndex        =   4
  62.       Top             =   600
  63.       Width           =   3135
  64.       Begin CommandButton cmdExit 
  65.          Caption         =   "E&xit"
  66.          Height          =   375
  67.          Index           =   0
  68.          Left            =   120
  69.          TabIndex        =   9
  70.          Top             =   1560
  71.          Width           =   2895
  72.       End
  73.       Begin Label lblDownRight 
  74.          Alignment       =   2  'Center
  75.          BorderStyle     =   1  'Fixed Single
  76.          Caption         =   "to the four corners!"
  77.          Height          =   255
  78.          Left            =   120
  79.          TabIndex        =   8
  80.          Top             =   1200
  81.          Width           =   2895
  82.       End
  83.       Begin Label lblDownLeft 
  84.          Alignment       =   2  'Center
  85.          BorderStyle     =   1  'Fixed Single
  86.          Caption         =   "and these labels will be moved"
  87.          Height          =   255
  88.          Left            =   120
  89.          TabIndex        =   7
  90.          Top             =   840
  91.          Width           =   2895
  92.       End
  93.       Begin Label lblUpRight 
  94.          Alignment       =   2  'Center
  95.          BorderStyle     =   1  'Fixed Single
  96.          Caption         =   "the picture box will be enlarged,"
  97.          Height          =   255
  98.          Left            =   120
  99.          TabIndex        =   6
  100.          Top             =   480
  101.          Width           =   2895
  102.       End
  103.       Begin Label lblUpLeft 
  104.          Alignment       =   2  'Center
  105.          BorderStyle     =   1  'Fixed Single
  106.          Caption         =   "When you click ""Start"","
  107.          Height          =   255
  108.          Left            =   120
  109.          TabIndex        =   5
  110.          Top             =   120
  111.          Width           =   2895
  112.       End
  113.    End
  114. ' scroll_1.FRM - Declarations.
  115.     DefInt A-Z
  116. ' End Of Declarations.
  117. Sub cmdExit_Click (Index As Integer)
  118. ' Completely self explanatory!
  119.     End
  120. End Sub
  121. Sub cmdStart_Click ()
  122. ' Hide the Start button right away.
  123.     cmdStart.Visible = False
  124. ' Move and enlarge the scrolling picture box.
  125. ' The "600, 400" can be changed to any reasonable size,
  126. ' up to a maximum of 16,383 by 16,383 pixels.
  127. ' If AutoRedraw=True then larger sizes use a _LOT_ more memory.
  128.     picBig.Move 0, 0, 600, 400
  129. ' Move the four labels out to the corners of picBig. These are not critical,
  130. ' and they aren't necessary for scrolling the picBig box.
  131.     lblUpLeft.Move 0, 0
  132.     lblUpRight.Move (picBig.Width - lblUpRight.Width), 0
  133.     lblDownLeft.Move 0, (picBig.Height - lblDownLeft.Height)
  134.     temp1 = picBig.Width - lblUpRight.Width
  135.     temp2 = picBig.Height - lblDownLeft.Height
  136.     lblDownRight.Move temp1, temp2
  137. ' Now duplicate the "Exit" command button a few times, just to have some
  138. ' other sample controls on the form. These are not critical, and can be
  139. ' removed and replaced with any other kind of control.
  140.     For temp = 1 To 7
  141.     Load cmdExit(temp)
  142.     Next temp
  143. ' Organize the little Exit buttons - just to have something else to scroll.
  144. ' The following code is NOT critical, and isn't necessary for scrolling the
  145. ' picBig box. You would normally put more MEANINGFUL controls onto the box,
  146. ' for example: Text boxes, command buttons, picture boxes, labels, option
  147. ' buttons, just about anything!
  148.     For x = 0 To 7
  149.     cmdExit(x).Move 75 + (x * 50), 50 + (x * 40), 100, 20
  150.     cmdExit(x).Visible = True
  151.     Next x
  152. ' Move the scroll bars to their correct locations.
  153.     Call FixScrollBars
  154. End Sub
  155. Sub FixScrollBars ()
  156. ' Assume you won't need to display anything.
  157.     vertFLAG = False
  158.     horizFLAG = False
  159.     cornerFLAG = False
  160. ' Figure out how much WIDTH of the picture box is hidden now,
  161. ' and if any width is hidden, you need a horizontal scroll bar.
  162.     HiddenX = (picBig.Width) - (frmMain.ScaleWidth)
  163.     If HiddenX > 0 Then horizFLAG = True
  164. ' Figure out how much HEIGHT of the picture box is hidden now,
  165. ' and if any height is hidden, you need a vertical scroll bar.
  166.     HiddenY = (picBig.Height) - (frmMain.ScaleHeight)
  167.     If HiddenY > 0 Then vertFLAG = True
  168. ' If horizontal scroll bar is ON, then slightly less height is available,
  169. ' so re-check the height.
  170.     If horizFLAG = True Then
  171.     HiddenY = (picBig.Height - 1) - (frmMain.ScaleHeight - hsb1.Height)
  172.     If HiddenY > 0 Then vertFLAG = True
  173.     End If
  174. ' If vertical scroll bar is ON, then slightly less width is available,
  175. ' so re-check the width.
  176.     If vertFLAG = True Then
  177.     HiddenX = (picBig.Width - 1) - (frmMain.ScaleWidth - vsb1.Width)
  178.     If HiddenX > 0 Then horizFLAG = True
  179.     End If
  180. ' If both scroll bars are ON, then turn on the corner box.
  181.     If (horizFLAG = True) And (vertFLAG = True) Then cornerFLAG = True
  182. ' At this point, you know if hsb1/vsb1/picCorner will be ON or OFF,
  183. ' so if anything will be OFF, make it invisible now. This section doesn't
  184. ' make anything visible, because if something is invisible, it's better
  185. ' to leave it that way until AFTER it is moved.
  186.     If horizFLAG = False Then hsb1.Visible = False
  187.     If vertFLAG = False Then vsb1.Visible = False
  188.     If cornerFLAG = False Then picCorner.Visible = False
  189. ' Move the vertical scroll bar over to the right side of the form,
  190. ' and make sure it's visible.
  191.     If vertFLAG = True Then
  192.     ' Top is always 0.
  193.         vsb1.Top = 0
  194.     ' Find the new height - but watch out for negative numbers.
  195.         tempVH = frmMain.ScaleHeight - hsb1.Height + 2
  196.         If horizFLAG = False Then tempVH = frmMain.ScaleHeight + 1
  197.         If tempVH > 0 Then vsb1.Height = tempVH
  198.     ' Find the new left - but watch out for negative numbers.
  199.         tempVL = frmMain.ScaleWidth - vsb1.Width + 1
  200.         If tempVL > 0 Then vsb1.Left = tempVL
  201.     ' Show it.
  202.         vsb1.Visible = True
  203.     End If
  204. ' Move the horizontal scroll bar down to the bottom of the form,
  205. ' and make sure it's visible.
  206.     If horizFLAG = True Then
  207.     ' Left is always 0.
  208.         hsb1.Left = 0
  209.     ' Find the new width - but watch out for negative numbers.
  210.         tempHW = frmMain.ScaleWidth - vsb1.Width + 2
  211.         If vertFLAG = False Then tempHW = frmMain.ScaleWidth + 1
  212.         If tempHW > 0 Then hsb1.Width = tempHW
  213.     ' Find the new top - but watch out for negative numbers.
  214.         tempHT = frmMain.ScaleHeight - hsb1.Height + 1
  215.         If tempHT > 0 Then hsb1.Top = tempHT
  216.     ' Show it.
  217.         hsb1.Visible = True
  218.     End If
  219. ' Move the little grey corner box to the lower right corner of the form.
  220. ' It's always the same width as vsb1, and the same height as hsb1,
  221. ' so even if those sizes are different, the corner will be perfect.
  222.     If cornerFLAG = True Then
  223.     picCorner.Move tempVL, tempHT, vsb1.Width, hsb1.Height
  224.     picCorner.Visible = True
  225.     End If
  226. ' Fix scroll bar values - so you can scroll to the hidden areas of picBig.
  227. ' These two lines are CRITICAL, and they're the key to the entire program.
  228.     vsb1.Max = HiddenY
  229.     hsb1.Max = HiddenX
  230. End Sub
  231. Sub Form_Resize ()
  232. ' Every time the form is resized, you need to move the scroll bars around.
  233.     Call FixScrollBars
  234. End Sub
  235. Sub hsb1_Change ()
  236. ' Move the picture box to the left (into invisible negative numbers).
  237. ' Note the MINUS SIGN before "hsb1.value".
  238.     picBig.Left = -hsb1.Value
  239. End Sub
  240. Sub vsb1_Change ()
  241. ' Move the picture box up (into invisible negative numbers).
  242. ' Note the MINUS SIGN before "vsb1.value".
  243.     picBig.Top = -vsb1.Value
  244. End Sub
  245.